using UnityEngine;
using QFramework;
using System;
using static UnityEngine.EventSystems.EventTrigger;

namespace survivor
{
	public partial class Enemy : ViewController
	{
		public float moveSpeed = 1.5f;

        public float HP = 3f;

        private void Start()
        {
            EnemyGenerator.EnemyCount.Value++;
        }

        private void OnDestroy()
        {
            if(EnemyGenerator.EnemyCount.Value<= 0) return;
            EnemyGenerator.EnemyCount.Value--;
        }

        private void Update()
        {
            if (HP <= 0)
            {
                Global.GeneratePowerUp(this.transform.position);
                this.DestroyGameObjGracefully();
            }

            if (Player.ins)
            {
                var direction = (Player.ins.transform.position - transform.position).normalized;
                 
                transform.Translate(direction * Time.deltaTime * moveSpeed);
            }
        }

        private void FixeUpdate(){
            
        }

        private bool mIgnoreHurt = false;
        internal void Hurt(float value)
        {
            if (mIgnoreHurt) return;
            Sprite.color = Color.red;
            ActionKit.Delay(0.2f, () =>
            {
                this.HP -= Global.SimpleAblityDamage.Value;
                this.Sprite.color = Color.white;
                mIgnoreHurt = false;    
            }).Start(this);
        }
    }
}
